# coding: utf8

# Модуль тестирует значимые для кода токены

import os
from ala_classes import TokenType
from scanner import PythonScanner

true_tokens = {
    'instructions': ['while', 'if', 'elif', 'else', 'for', 'in', 'print', 'pass', 'break'],

    'values': ['True', 'False',  # bool values
               '10',  # int values
               '"lol"', "'lol'",   # str values
               '[]', '[1]', '[1,2]', '[1,2,3,]',   # list of int
               "['1']", "['1','2']", '["1"]', '["1","2"]',  # list of str
               """['1',"2"]""", """["1","2"]"""],  # different string literal in list of str

    'logic_expression': ['!=', '==', '>', '>=', '<', '<=', 'and', 'or', 'not'],

    'arithmetic_expression': ['+', '-', '//', '*', '(', ')'],

    'ID': ['abc', 'a1', 'a12a', 'a1a2', 'a_1', 'a_1_a_2', 'a_', 'a1_', '_a', '_a1', '_1', '__12a', '_1_', '_a_'],

    'assign': ['=']
}


def scanner_test():
    for token_type in true_tokens.keys():
        for token in true_tokens[token_type]:
            with open('./file.tmp', 'w') as f:
                f.write(token)

            with open('./file.tmp') as f:
                is_have_error = False
                scanner = PythonScanner(f)
                tokens = scanner.get_all_tokens()
                for result_token in tokens:
                    if result_token.type == TokenType.ERROR:
                        print 'Исходная строка:', token, 'Ошибка в токене:', result_token
                        is_have_error = True
                if is_have_error:
                    print

        os.remove('./file.tmp')